<?php
require_once FOREGROUND_COMMON_ACTION_SERVICE_DIR . '/default.php';

class foreground_index_action_service extends foreground_default_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {
        $cache_handler = wwy_resource_container::get_cache_handler();
        
        //获取一级分类
        $model_foreground_good_category = wwy_resource_container::get_model_foreground_good_category();
        $parent_cat_id = 0;
        //$direct_children_cat_list = $model_foreground_good_category->get_direct_children($parent_cat_id);
        $direct_children_cat_list = $cache_handler->call(array($model_foreground_good_category, 'get_direct_children'), array($parent_cat_id));
        //var_dump($direct_children_cat_list); exit();
        
        $direct_children_cat_good_list = array();
        $model_foreground_good = wwy_resource_container::get_model_foreground_good();
        $page_num = 1;
        $item_count = 10;
        $page_range = 1;
        $order = array('`order` asc', 'id desc');
        $options = array('item_count' => $item_count, 'page_num' => $page_num, 'page_range' => $page_range);
        foreach ($direct_children_cat_list as $key => $direct_children_cat){                                             
            $where = array('status' => 1);           
            //$self_children_id_list = $model_foreground_good_category->get_self_children_id_list($direct_children_cat['id']);
            $self_children_id_list = $cache_handler->call(array($model_foreground_good_category, 'get_self_children_id_list'), array($direct_children_cat['id']));
            $where['cat_ids'] = $self_children_id_list;
            
            //$good_list = $model_foreground_good->get_list($where, $order, $options);   
            $good_list = $cache_handler->call(array($model_foreground_good, 'get_list'), array($where, $order, $options));
            $direct_children_cat_good_list[$key] = $good_list['list'];
        }
        //var_dump($direct_children_cat_good_list); exit();
        
        self::add_view_data('direct_children_cat_list', $direct_children_cat_list);
        self::add_view_data('direct_children_cat_good_list', $direct_children_cat_good_list);
        
        //self::add_view_data('if_index_page', '1');
        //SEO:title,keywords,description
        self::add_view_data('page_title', '首页');
    }
}